package leetcode_600;

import java.util.Arrays;

/**
 *@author 周杨
 *RelativeRanks_506 给一个Int数组里的元素排名
 *describe:为了不破坏原有数组index 复制数组然后二分查找 AC 60%
 *2018年9月6日 上午9:47:49
 */
public class RelativeRanks_506 {
	public String[] findRelativeRanks(int[] nums) {
		if(nums.length==0)
			return new String[] {};
		int copy[]=Arrays.copyOf(nums, nums.length);
		String res[]=new String[nums.length];
		Arrays.sort(copy);
		for(int i=0;i<nums.length;++i) {
			int index=Arrays.binarySearch(copy, nums[i]);
			if(index==nums.length-1)
				res[i]="Gold Medal";
			else if(index==nums.length-2)
				res[i]="Silver Medal";
			else if(index==nums.length-3)
				res[i]="Bronze Medal";
			else 
				res[i]=String.valueOf(nums.length-index);
		}
		return res;
    }
}
